<?php include('../../variables/variables.php'); ?>

<?php

if(!session_id()) session_start(); 
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if ($con)
{
	mysql_select_db($db, $con);
	

	if (isset($_POST['mediaID']) && $_POST['mediaID'])
	{
		
		$q = fquery($get_book_exists, array($_POST['mediaID']));
		$result = mysql_query($q);
		$result = mysql_num_rows($result);
		mysql_close($con);
		if ($result)
		{
			header("location: /manage_inventory.php?action=display&id=". $_POST['mediaID'] );
		}
		else
		{
			header("location: /manage_inventory.php?&err=invalid ID");
		}
	}
	else if (isset($_POST['isbn']) && $_POST['isbn'])
	{
		
		$q = fquery($get_book_exists_by_isbn, array($_POST['isbn']));
		$result = mysql_query($q);
		$result = mysql_fetch_array($result);
		mysql_close($con);
		if ($result['media_id'])
		{
			header("location: /manage_inventory.php?action=display&id=". $result['media_id'] );
		}
		else
		{
			header("location: /manage_inventory.php?err=invalid ID");
		}
	}
	else if (isset($_POST['inventory_id']) && $_POST['inventory_id'])
	{
		
		$q = fquery($get_inventory_exists, array($_POST['inventory_id']));
		$result = mysql_query($q);
		$result = mysql_fetch_array($result);
		mysql_close($con);
		if ($result['inventory_id'])
		{
			header("location: /manage_inventory.php?action=modify&id=". $result['inventory_id'] );
		}
		else
		{
			header("location: /manage_inventory.php?err=invalid ID");
		}
	}
	else
	{
		mysql_close($con);
		header("location: /manage_inventory.php?err=Fill in search!");
	}
}

?>
